package org.eclipse.wst.server.preview.openejb.jetty.loader;

import org.mortbay.component.LifeCycle;

/**JettyListener : To make OpenEJB container available as soon 
 * as Jetty web server starts we have created a listener responsible
 * to listen the stating process of Jetty and trigger the embedding 
 * of OpenEJB container as soon as the Jetty server is started. 
 * This class do that calling JettyEmbedder.embed( ClassLoader loader ), 
 * passing the ClassLoader that loaded the Jetty server when it 
 * listens the lifeCycleStarted event from Jetty.
 * 
 * @author Marcelo de Oliveira Dias
 */
public class JettyListener implements LifeCycle.Listener  {

	private boolean openejbLoaded = false;
	
	public void lifeCycleFailure(LifeCycle arg0, Throwable arg1) {
	}

	/**Embeds the OpenEJB in the Jetty as sooner as the Jetty is started.
	 */
	public void lifeCycleStarted(LifeCycle event) {
		if (openejbLoaded) return;
		JettyEmbedder.embed();
		openejbLoaded = true;
	}

	public void lifeCycleStarting(LifeCycle arg0) {
	}

	public void lifeCycleStopped(LifeCycle arg0) {
	}

	public void lifeCycleStopping(LifeCycle arg0) {
	}

}
